import java.applet.*;
import java.awt.*; 

public class PressureDemo 
{
	int height;
	int width;

	double ballpos;
	double initvel;
	double pistonpos;

	public PressureDemo(int w, int h, double pispos, double bpos, double v)
{
		height = w; width = h; pistonpos = pispos; ballpos= bpos;
		initvel=v;
		}

	public PressureDemo(int w, int h) {
		this(w,h,1,5,4);
		}

	public void setSize( int w, int h ) { height = h; width = w; }
	
	public void setBPos(double bpos) {
		ballpos=bpos;
	}

	public void setPistonPos(double pispos) {
		pistonpos = pispos;
	}

	public void setVel(double vel) {
		initvel = vel;
	}

	public void draw( Graphics g ) {
		int h = height; 
		int w = width;  
		double v=initvel,a,b,c, t=0.15, gr=4, tmp=1,pv=0;
		double m=1,M=5;
		double ppos= pistonpos;
		double bpos=ballpos;
		int x0=100,y0=100;
		g.clearRect(0,0,w,h);
		g.setColor(Color.black);
		g.fillRect(x0,y0,2,200);
		g.fillRect(x0+100,y0,2,200);
		g.fillRect(x0,y0+200,100,2);
		g.setColor(Color.red);
		g.fillRect(x0+2,y0+(int)(ppos),100,5);
		g.fillRect(x0+48,y0+(int)(ppos)-60,4,60);
		g.setColor(Color.blue);
		g.fillOval(x0+50,y0+(int)(bpos),5,5);
	}
}
















/*           if (bpos>ppos+10 && bpos<180)
            {
              v=v+gr*t;
              bpos=bpos+v*t;
              pv=pv+gr*t;
              ppos=ppos+pv*t;
            }
            else if(bpos<ppos+10 )
            {
             tmp=pv;
             a=1+M/m;
             b=-pv*M/m +v;
             c=M*pv*pv/m + 2*v*pv - pv*pv ;
             pv=(-b+Math.sqrt(b*b-a*c))/a;
             a=1+m/M;
             b=-v*m/M +tmp;
             c=m*v*v/M + 2*tmp*v - v*v ;
             v=(-b+Math.sqrt(b*b-a*c))/a;
              v=v+gr*t;
              bpos=bpos+v*t;
              pv=pv+gr*t;
              ppos=ppos+pv*t;
            }
             else if(bpos>180)
            {
              v=-v;
              v=v+gr*t;
              bpos=bpos+v*t;
              pv=pv+gr*t;
              ppos=ppos+pv*t;
	    }     	*/

